//
//  PublicDefine.swift
//  DiZhenYuJing
//
//  Created by zhibao on 2024/2/2.
//

import Foundation
func DLog<T>(message: T,
                 file: String = #file,
                 line: Int = #line)
{
    let fileName = (file as NSString).lastPathComponent
    print("\(fileName)第\(line)行：\(message)")
}

let SCREEN_WIDTH = UIScreen.main.bounds.width
let SCREEN_HEIGHT = UIScreen.main.bounds.height
let kMainScreenBounds = UIScreen.main.bounds

//颜色切换定义

let MYRed = MYColor.color(withHexString:"#E04148")
let MYOrange = MYColor.color(withHexString:"#FFD640")
let MYBlue = MYColor.color(withHexString:"#2666e4")
let MYGreen = MYColor.color(withHexString:"#1EA61E")
let ThemeColor = MYColor.color(withHexString:"#0F1011")
let ciThemeColor = MYColor.color(withHexString:"#25282D")
let MYBlock = MYColor.color(withHexString:"#333333")

func LocalizedString(_ key:String) -> String {
    return NSLocalizedString(key, comment: "")
}

//自定义字体或系统其他字体
func kNumberFONT(_ R:CGFloat) -> UIFont!{
    return UIFont.init(name: "DIN Alternate", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

//普通字体
func MY_SCALE_FONT(_ R:CGFloat) -> UIFont! {
    return UIFont.systemFont(ofSize: pixw(p: R))
}

//默认加粗字体
func MY_SCALE_BoldFont(_ R:CGFloat) -> UIFont! {
    return UIFont.boldSystemFont(ofSize: pixw(p: R))
}

//PingFangSC-Regular
func MY_SCALE_RegularFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Light", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

func MY_SCALE_HeavyFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Semibold", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

func MY_SCALE_LightFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Light", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

func MY_SCALE_UltralightFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Ultralight", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

func MY_SCALE_ThinFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Thin", size: pixw(p: R)) ?? MY_SCALE_FONT(R)
}

func MY_SCALE_MediumFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Medium", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

func MY_SCALE_SemiboldFONT(_ R:CGFloat) -> UIFont! {
    return UIFont(name: "PingFangSC-Semibold", size: pixw(p: R)) ?? MY_SCALE_FONT(pixw(p: R))
}

//heavy
func KHFONT(_ R:CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: pixw(p: R), weight: .heavy)
}


//根据当前屏幕宽度得到宽度
func pixw(p:CGFloat) ->CGFloat{
    return (SCREEN_WIDTH/395.0)*p
}

//根据当前屏幕高度得到高度
func pixh(p:CGFloat) ->CGFloat{
    return (SCREEN_HEIGHT/395)*p
}

func RGBA(_ r:CGFloat,_ g:CGFloat,_ b:CGFloat,_ a:CGFloat) ->UIColor{
    return UIColor(red: r / 255, green: g / 255, blue: b / 255, alpha: a)
}

/// 顶部安全区高度
func safeDistanceTop() -> CGFloat {
    let scene = UIApplication.shared.connectedScenes.first
    guard let windowScene = scene as? UIWindowScene else { return 0 }
    guard let window = windowScene.windows.first else { return 0 }
    return window.safeAreaInsets.top
}

/// 底部安全区高度
func safeDistanceBottom() -> CGFloat {
    let scene = UIApplication.shared.connectedScenes.first
    guard let windowScene = scene as? UIWindowScene else { return 0 }
    guard let window = windowScene.windows.first else { return 0 }
    return window.safeAreaInsets.bottom
}

/// 顶部状态栏高度（包括安全区）
 func statusBarHeight() -> CGFloat {
    var statusBarHeight: CGFloat = 0
     let scene = UIApplication.shared.connectedScenes.first
     guard let windowScene = scene as? UIWindowScene else { return 0 }
     guard let statusBarManager = windowScene.statusBarManager else { return 0 }
     statusBarHeight = statusBarManager.statusBarFrame.height
    return statusBarHeight
}

/// 导航栏高度
func navigationBarHeight() -> CGFloat {
    return 44.0
}

/// 状态栏+导航栏的高度
func navigationFullHeight() -> CGFloat {
    return statusBarHeight() + navigationBarHeight()
}

/// 底部导航栏高度
 func tabBarHeight() -> CGFloat {
    return 49.0
}

/// 底部导航栏高度（包括安全区）
 func tabBarFullHeight() -> CGFloat {
    return tabBarHeight() + safeDistanceBottom()
}

/// 获取当前window
func keyWindow() -> UIWindow {
    if #available(iOS 15.0, *) {
        let keyWindow = UIApplication.shared.connectedScenes
            .map({ $0 as? UIWindowScene })
            .compactMap({ $0 })
            .first?.windows.first ?? UIWindow()
        return keyWindow
    }else {
        let keyWindow = UIApplication.shared.windows.first ?? UIWindow()
        return keyWindow
    }
}

let blurEffectTag = 123456
//增加模糊效果，添加按钮
func addbulrEffectView(superView:UIView,title:String = "会员解锁"){
    return
//    if MYGlobal.share().shenHeFlag == 1 {
//        return
//    }
//    
//    if UserInfoManager.shared().isVip() == true {
//        return
//    }
    
    superView.clipsToBounds = true
    // 设置背景颜色，以便在没有模糊效果时能看到对比
    let overView = UIView()
    overView.tag = blurEffectTag
    superView.addSubview(overView)
    overView.snp.makeConstraints { make in
        make.top.left.bottom.right.equalTo(superView)
    }
    
    // 创建一个 UIVisualEffectView 用于模糊效果
    let blurEffect = UIBlurEffect(style: .regular) // 选择模糊效果风格，.light 或 .dark 或 .regular（如果支持）
    let blurView = UIVisualEffectView(effect: blurEffect)
    
    // 将 blurView 添加到主视图中
    overView.addSubview(blurView)
    // 设置 blurView 的大小和位置
    blurView.snp.makeConstraints { make in
        make.top.left.bottom.right.equalTo(overView)
    }
    
    // 创建一个按钮
    let button = UIButton(type: .system)
    button.setTitle(title, for: .normal)
//    if UserInfoManager.shared().isLogin == false{
//        button.setTitle("请登录", for: .normal)
//    }
    button.titleLabel?.font = MY_SCALE_BoldFont(18)
    
    // 设置按钮的颜色和其他属性
    button.backgroundColor = MYOrange
    button.layer.cornerRadius = pixw(p: 10) // 圆角
    // 将按钮添加到 blurView 上（或 self.view 上，如果你想要按钮在模糊效果之上）
    blurView.contentView.addSubview(button) // 添加到 blurView 的 contentView 中，以确保按钮在模糊效果之上
    
    // 设置按钮的位置和大小
    button.snp.makeConstraints { make in
        make.center.equalTo(blurView)
        make.width.equalTo(pixw(p: 150))
        make.height.equalTo(pixw(p: 60))
    }
    
    button.addGestureRecognizer(UITapGestureRecognizer(actionBlock: { sender in
        let controller = PayMarkController()
        MYGlobal.share().lastVC.navigationController?.pushViewController(controller, animated: true)
        
    }))
}

let earthquakeData: [[String: Any]] = [
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CC20241106223625",
        "CATA_TYPE": "",
        "EPI_DEPTH": 60,
        "EPI_LAT": "-4.95",
        "EPI_LON": "153.15",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "巴布亚新几内亚附近海域",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "5.9",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-06 22:36:24",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-06 23:02:09",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-06 23:02:12",
        "id": 50933,
        "t": 3
    ],
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CD20241107011939",
        "CATA_TYPE": "",
        "EPI_DEPTH": 20,
        "EPI_LAT": "23.59",
        "EPI_LON": "121.61",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "台湾花莲县海域",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "4.5",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-07 01:19:39",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-07 01:29:06",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-07 01:29:16",
        "id": 50934,
        "t": 3
    ],
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CC20241107041953",
        "CATA_TYPE": "",
        "EPI_DEPTH": 10,
        "EPI_LAT": "29.85",
        "EPI_LON": "92.25",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "西藏拉萨市墨竹工卡县",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "4.5",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-07 04:19:53",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-07 04:30:01",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-07 04:30:08",
        "id": 50935,
        "t": 3
    ],
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CC20241107065511",
        "CATA_TYPE": "",
        "EPI_DEPTH": 60,
        "EPI_LAT": "25.55",
        "EPI_LON": "142.85",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "日本火山列岛地区",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "5.8",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-07 06:55:11",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-07 07:24:34",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-07 07:24:40",
        "id": 50936,
        "t": 3
    ],
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CD20241107183110",
        "CATA_TYPE": "",
        "EPI_DEPTH": 10,
        "EPI_LAT": "41.04",
        "EPI_LON": "115.23",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "河北张家口市崇礼区",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "3.6",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-07 18:31:09",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-07 18:36:17",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-07 18:36:23",
        "id": 50937,
        "t": 3
    ],
    [
        "AUTO_FLAG": "M",
        "CATA_ID": "CC20241108003034",
        "CATA_TYPE": "",
        "EPI_DEPTH": 10,
        "EPI_LAT": "20.75",
        "EPI_LON": "99.9",
        "EQ_CATA_TYPE": "",
        "EQ_TYPE": "M",
        "IS_DEL": "",
        "LOCATION_C": "缅甸",
        "LOCATION_S": "",
        "LOC_STN": 0,
        "M": "4.2",
        "M_MB": 0,
        "M_MB2": 0,
        "M_ML": 0,
        "M_MS": 0,
        "M_MS7": 0,
        "O_TIME": "2024-11-08 00:30:33",
        "O_TIME_FRA": 0,
        "SAVE_TIME": "2024-11-08 00:55:03",
        "SUM_STN": 0,
        "SYNC_TIME": "2024-11-08 00:55:10",
        "id": 50938,
        "t": 3
    ]
]
